home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / warp_tri.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  91 lines

  1. ; $Id: warp_tri.pro,v 1.5 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1992-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. function warp_tri, xo, yo, xi, yi, im_in, OUTPUT_SIZE = output_size, $
  7.     QUINTIC = quintic, EXTRAPOLATE = extra
  8. ; xo, yo = coordinates of tie points in output image.
  9. ; xi, yi = coordinates of tie points in im_in.
  10. ;+
  11. ; NAME:
  12. ;    WARP_TRI
  13. ;
  14. ; PURPOSE:
  15. ;    This function warps images using control (tie) points.
  16. ;
  17. ; CATEGORY:
  18. ;    Image processing, geometric transformation.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;    Result = WARP_TRI(Xo, Yo, Xi, Yi, Im_in)
  22. ;
  23. ; INPUTS:
  24. ;    Xo, Yo:         Vectors containing the locations of the tie points
  25. ;             in the output image.
  26. ;    Xi, Yi:         Vectors containing the location of the tie points
  27. ;             in the input image (Im_in). Xi, Yi must be the same
  28. ;             length as Xo, Y0.
  29. ;    Im_in:         The image to be warped. May be any type of data.
  30. ;
  31. ; KEYWORD PARAMETERS:
  32. ;    OUTPUT_SIZE: A 2-element vector containing the size of the
  33. ;             output image. If omitted, the output image is the
  34. ;             same size as Im_in.
  35. ;    QUINTIC:     Set this keyword to use smooth quintic interpolation.
  36. ;             Quintic interpolation is slower but the
  37. ;             derivatives are continuous across triangles,
  38. ;             giving a more pleasing result than the default
  39. ;             linear interpolation. 
  40. ;    EXTRAPOLATE: Set to true to extrapolate outside the convex
  41. ;             hull of the tie points. Setting this keyword implies
  42. ;             the use of QUINTIC interpolation.
  43. ;
  44. ; OUTPUTS:
  45. ;    This function returns an image array with the specified
  46. ;    geometric correction applied. Points at locations (Xi, Yi)
  47. ;    are shifted to (Xo, Yo).
  48. ;
  49. ; PROCEDURE:
  50. ;    The irregular grid defined by (Xo, Yo) is triangulated
  51. ;    using TRIANGULATE. Then the surfaces defined by (Xo, Yo, Xi)
  52. ;    and (Xo, Yo, Yi) are interpolated using TRIGRID to get
  53. ;    the locations in the input image of each pixel in the output
  54. ;    image. Finally, INTERPOLATE is called to obtain the result.
  55. ;    Linear interpolation is used by default.  Smooth quintic
  56. ;    interpolation is used if the QUINTIC keyword is set.
  57. ;
  58. ; MODIFICATION HISTORY:
  59. ;    DMS, Jan, 1992.
  60. ;    DMS, Jul, 1992, added quintic interpolation.
  61. ;-
  62.  
  63. s = SIZE(im_in)
  64. if s[0] ne 2 then MESSAGE, 'Warp_tri - Im_in param must be 2D'
  65.  
  66. TRIANGULATE, xo, yo, tr, bounds
  67.  
  68. if n_elements(output_size) ge 2 then begin
  69.     nx = output_size[0]
  70.     ny = output_size[1]
  71. endif else begin
  72.     nx = s[1]
  73.     ny = s[2]
  74. endelse
  75.  
  76. gs = [1,1]                ;Grid spacing
  77. b = [0,0, nx-1, ny-1]            ;Bounds
  78.  
  79. ; This style is called early schizophrenic capitalization.
  80.  
  81. if KEYWORD_SET(extra) then $
  82.     return, INTERPOLATE(im_in,  $
  83.       TRIGRID(xo,yo,xi,tr, gs, b, /QUINT, EXTRA = bounds), $
  84.       TRIGRID(xo,yo,yi,tr, gs, b, /QUINT, EXTRA = bounds))$
  85. ELSE $
  86.     return, INTERPOLATE(im_in, $
  87.       TRIGRID(xo,yo,xi,tr, gs, b, QUINT=KEYWORD_SET(quintic)), $
  88.       TRIGRID(xo,yo,yi,tr, gs, b, QUINT=KEYWORD_SET(quintic)))
  89. end
  90.  
  91.